<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\assets;

use yii\helpers\Json;
use yii\web\AssetBundle;

/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot/mobile';
    public $baseUrl = '@web';
    public $css = [];
    public $js = [
        'http://res.wx.qq.com/open/js/jweixin-1.0.0.js',
        '//cdn.bootcss.com/zepto/1.1.6/zepto.min.js',
    ];
    public $depends = [
        'app\assets\iScrollAsset'
    ];

    public function init()
    {
        parent::init();
        if (false) {
            $this->baseUrl = 'http://192.168.0.144:8010';
            $this->css = ['mobile/dist/style.css'];
            $this->js = [
                'http://res.wx.qq.com/open/js/jweixin-1.0.0.js',
                '//cdn.bootcss.com/zepto/1.1.6/zepto.min.js',
                'webpack-dev-server.js',
                'mobile/dist/mobile.bundle.js'
            ];
        } else {
            $asset = file_get_contents(__DIR__ . '/../web/mobile/dist/manifest.json');
            $asset = Json::decode($asset);
            foreach ($asset as $sectionName => $section) {
                if (isset($section['js'])) {
                    $this->js[] = $section['js'];
                }
                if (isset($section['css'])) {
                    $this->css[] = $section['css'];
                }
            }
        }
    }


}
